// pages/index/test_list/test_list.js
Page({


  /**
   * 页面的初始数据
   */
  data: {
    height: {
      value: '1.58',
      unit: 'M'
    },
    weight: {
      value: '50',
      unit: 'KG'
    },
    sex: {
      value: 0,
      unit: ''
    },
    age: {
      value: '20',
      unit: '岁'
    },
    plan: {
      value: 1,
      unit: ''
    },
    targetWeight: {
      value: '50',
      unit: 'KG'
    },
    planOptions: ['增肌', '减脂'],
    sexOptions: ['女性', '男性']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 从缓存中取数据
    let healthy_report_source = wx.getStorageSync('healthy_report_source')
    if (healthy_report_source) {
      this.setData({
        height: {
          value: healthy_report_source.height,
          unit: 'M'
        },
        weight: {
          value: healthy_report_source.weight,
          unit: 'KG'
        },
        sex: {
          value: healthy_report_source.sex,
          unit: ''
        },
        age: {
          value: healthy_report_source.age,
          unit: '岁'
        },
        plan: {
          value: healthy_report_source.plan,
          unit: ''
        },
        targetWeight: {
          value: healthy_report_source.targetWeight,
          unit: 'KG'
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  bindinputHeight(e) {
    console.log('input', e.detail.value)
    this.setData({
      height: {
        value: e.detail.value,
        unit: 'CM'
      }
    })
  },
  bindinputWeight(e) {
    console.log('input', e.detail.value)
    this.setData({
      weight: {
        value: e.detail.value,
        unit: 'KG'
      }
    })
  },
  bindinputSex(e) {
    console.log('input', e.detail.value)
    this.setData({
      sex: {
        value: e.detail.value,
        unit: ''
      }
    })
  },
  bindinputAge(e) {
    console.log('input', e.detail.value)
    this.setData({
      age: {
        value: e.detail.value,
        unit: '岁'
      }
    })
  },
  bindinputPlan(e) {
    console.log('input', e.detail.value)
    this.setData({
      plan: {
        value: e.detail.value,
        unit: ''
      }
    })
  },
  bindinputTargetWeight(e) {
    console.log('input', e.detail.value)
    this.setData({
      targetWeight: {
        value: e.detail.value,
        unit: 'KG'
      }
    })
  },
  bindPickerChangeSex: function (e) {
    console.log('sex picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      sex: { value: e.detail.value, unit: '' }
    })
  },
  bindPickerChangePlan: function (e) {
    console.log('plan picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      plan: { value: e.detail.value, unit: '' }
    })
  },
  saveReportSource(e) {
    // 保存数据到缓存
    let data = this.data
    console.log(data)
    wx.setStorageSync('healthy_report_source', {
      height: data.height.value,
      weight: data.weight.value,
      sex: data.sex.value,
      age: data.age.value,
      plan: data.plan.value,
      targetWeight: data.targetWeight.value
    })
    // 跳转到评测结果
    wx.navigateTo({
      url: '../health_report/health_report'
    })
  }
})